import cv2 as cv
import sys
import os
from python_ai.common.xcommon import *
import matplotlib.pyplot as plt
import numpy as np

cam_idx = 0
try:
    cap = cv.VideoCapture(cam_idx)
except cv.error as ex:
    print(f'Cannot open camera {cam_idx}')
    print(ex)
    sys.exit(1)

if not cap.isOpened():
    print(f'Cannot open camera {cam_idx}')

ret, frame = cap.read()

if not ret:
    print('Cannot receive frame. Exiting ...')
    sys.exit(0)

print(frame.shape)  # (480, 640, 3)

# frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)  # no need, my cam is alread RGB

cv.imshow('Cam', frame)


